<?php
	require_once('db_connect.php');
	$user_id = $_COOKIE['user_id'];
	$query = "SELECT * from member where id = '$user_id'";
	$data = mysqli_query($conn, $query)
		or die("$user_id 로 회원 정보 가져오기 쿼리 실패");
	if (mysqli_num_rows($data) <= 0)
		exit("$user_id 의 회원이 DB에 없음");
	$row = mysqli_fetch_array($data);
	
	$query = "select * from category_mem where mem_id = '$user_id'";
	$catedata = mysqli_query($conn, $query)
		or die("$user_id 의 관심 카테고리 가져오는 쿼리 실패");
	if (mysqli_num_rows($catedata) <= 0)
		exit("$user_id 의 관심카테고리가 DB에 없음");
	$user_categories = "";
	while ($caterow = mysqli_fetch_array($catedata)) {
		$user_categories .= $caterow['category'].',';
	}
	$user_categories = trim($user_categories, ",");
	
	$query = "select * from keyword_mem where mem_id = '$user_id'";
	$kwdata = mysqli_query($conn, $query)
		or die("$user_id 의 관심 키워드 가져오는 쿼리 실패");
	if (mysqli_num_rows($kwdata) <= 0)
		exit("$user_id 의 관심 키워드가 DB에 없음");
	$user_keywords = "";
	while ($kwrow = mysqli_fetch_array($kwdata)) {
		$user_keywords .= $kwrow['keyword'].',';
	}
	$user_keywords = trim($user_keywords, ",");
?>
<script type="text/javascript">
	$('document').ready(function() {
		if (!(document.getElementById('survey_list')))
			$('#show_own_survey').hide();
		$('#make_survey').click(function() {
			window.location = "survey_form.php";
		});
		$('#show_own_survey').click(function() {
			var query = buildQuery(null, null, null, null, "<?php echo $row['id']; ?>");
			printSurveyListBy(query, false);
		});
	});
</script>
<div id="member_info">
<h3>회원정보</h3>
<table>
<tbody>
	<tr>
		<th class="label">ID</th>
		<td><?php echo $row['id']; ?></td>
	</tr>
	<tr>
		<th class="label">이름</th>
		<td><?php echo $row['name']; ?></td>
	</tr>
	<tr>
		<th class="label">성별</th>
		<td><?php echo ($row['gender'] == 1 ? '남' : '여'); ?></td>
	</tr>
	<tr>
		<th class="label">연령</th>
		<td><?php echo $row['age']; ?></td>
	</tr>
	<tr>
		<th class="label">학력</th>
		<td><?php
					$edulevel = '';
					switch ($row['edulevel']) {
					case '1': echo '중졸 이하'; break;
					case '2': echo '고졸'; break;
					case '3': echo '초대졸'; break;
					case '4': echo '대졸'; break;
					case '5': echo '대학원졸 이상'; break;
					}
				?>
		</td>
	</tr>
	<tr>
		<th class="label">거주지</th>
		<td><?php echo $row['addr']; ?></td>
	</tr>
	<tr>
		<th class="label">관심카테고리</th>
		<td><?php echo $user_categories; ?></td>
	</tr>
	<tr>
		<th class="label">관심키워드</th>
		<td><?php echo $user_keywords; ?></td>
	</tr>
</tbody>
</table>
<form>
	<input type="button" id="make_survey" value="설문만들기" />
	<input type="button" id="show_own_survey" value="내 설문보기" />
</form>
</div>